package org.wevil.anno;

import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;

/**
 * 自定义内省器
 */
public class CustomIntrospector extends NopAnnotationIntrospector {

    @Override
    public Object findSerializer(Annotated am) {
        DataMasking annotation = am.getAnnotation(DataMasking.class);
        if(annotation!=null){
            // 给序列化类传入脱敏具体方法
            return new DataMaskingSerializer(annotation.maskFunc().getOperation());
        }
        NumberFormat numberFormatAnno = am.getAnnotation(NumberFormat.class);
        if(numberFormatAnno!=null){
            int scale = numberFormatAnno.scale();
            boolean b = numberFormatAnno.rightZero();
            boolean comma = numberFormatAnno.comma();
            return new NumberFormatSerializer(scale, b, comma);
        }
        // 默认序列化方法
        return super.findSerializer(am);
    }
}
